package com.jnevision.appverson.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.api.ApiController;
import com.baomidou.mybatisplus.extension.api.R;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
/**
 * <p>
 * APP版本控制 前端控制器
 * </p>
 *
 * @author gavin
 * @since 2019-07-21
 */
import com.jnevision.appverson.model.AppVersion;
import com.jnevision.appverson.service.AppVersionServiceImpl;

@RestController
@RequestMapping("/appversons")
public class AppVersionController extends ApiController {

    @Autowired
    private AppVersionServiceImpl appVersionServiceImpl;

    @PostMapping
    public R<Boolean> add(@RequestBody AppVersion appVersion) {

        return this.success(this.appVersionServiceImpl.save(appVersion));
    }

    @PutMapping
    public R<Boolean> update(@RequestBody AppVersion appVersion) {

        return this.success(this.appVersionServiceImpl.updateById(appVersion));
    }

    @DeleteMapping
    public R<Boolean> delete(String id) {
        return this.success(this.appVersionServiceImpl.removeById(id));
    }

    @GetMapping
    public R<AppVersion> get(String id) {
        return this.success(this.appVersionServiceImpl.getById(id));
    }

    @GetMapping("/page")
    public R<IPage<AppVersion>> page(Page<AppVersion> page) {
        return this.success(this.appVersionServiceImpl.page(page));
    }

    @GetMapping("/current")
    public R<AppVersion> all() {
        return this.success(this.appVersionServiceImpl.list().get(0));
    }
}
